﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;

namespace ZHJPMGR_WebApplication.PublicService
{
    /// <summary>
    /// LocalCommunicate 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
     [System.Web.Script.Services.ScriptService]
    public class LocalCommunicate : System.Web.Services.WebService
    {
        private static System.Net.CookieContainer cookieContainer;
        static LocalCommunicate()
        {
            cookieContainer = new System.Net.CookieContainer();
        }

        [WebMethod(EnableSession=true)]
        public string GetData(string userId, string taskGuid, string dataGuid, string dataType)
        {
            LogisticsInfoSystemService.Communicate webService = new LogisticsInfoSystemService.Communicate();
            webService.CookieContainer = cookieContainer;
            return webService.GetData(userId, taskGuid, dataGuid, dataType);
        }

        [WebMethod(EnableSession = true)]
        public int SetData(string userId, string taskGuid, string dataGuid, string dataType, string xmlData)
        {
            LogisticsInfoSystemService.Communicate webService = new LogisticsInfoSystemService.Communicate();
            webService.CookieContainer = cookieContainer;
            xmlData = xmlData.Replace("&lt;", "<");
            xmlData = xmlData.Replace("&gt;", ">");
            return webService.SetData(userId, taskGuid, dataGuid, dataType, xmlData);
        }

        [WebMethod(EnableSession = true)]
        // [ValidateInput(false)]
        public string TransformData(string userId, string taskGuid, string XmlTransform)
        {
            LogisticsInfoSystemService.Communicate webService = new LogisticsInfoSystemService.Communicate();
            webService.CookieContainer = cookieContainer;
            XmlTransform = XmlTransform.Replace("&lt;", "<");
            XmlTransform = XmlTransform.Replace("&gt;", ">");
            return webService.TransformData(userId, taskGuid, XmlTransform);
        }

        [WebMethod(EnableSession = true)]
        // [ValidateInput(false)]
        public int SaveLog(string fileName, string logContent)
        {

            string filePath = System.Configuration.ConfigurationManager.AppSettings["RequestLogFolder"];
            if (filePath == "" || filePath == null)
            {
                filePath = Server.MapPath("/Local/");
            }
            if (filePath.Substring(filePath.Length - 1, 1) != "\\") { filePath += "\\"; }
            filePath += fileName;
            StreamWriter logFile = new StreamWriter(filePath);
            logFile.Write(logContent);
            logFile.Close();
            return 0;
        }
    }
}
